<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="/layuiadmin/layui/css/layui.css" media="all"/>
    <link rel="stylesheet" href="/layuiadmin/style/admin.css" media="all"/>
</head>
<body>
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body layui-table-body layui-table-main">
            <form class="layui-form" action="" class="layui-form layui-form-pane" lay-filter="layui-form-pane" id="sbumitForm">
            <table class="layui-table layui-form" style="table-layout:fixed">
                <tbody>
                <?php foreach($conf as $key => $value) {?>
                <tr>
                    <td style="text-align: center;width: 50px;padding-right: 1px;border-right: 0px;">奖品<?php echo ($key + 1)?></td>
                    <td style="text-align: center;width: 150px;padding-left: 1px;border-left: 0px">
                        <select name="lottery_award_id[]"  lay-filter="lottery_award_id" data="<?php echo $key;?>">
                            <option value="" >选择奖品</option>
                            <?php foreach($list as $item){?>
                            <option value="<?php echo $item['id'];?>" <?php if ($item['id'] == $value['lottery_award_id']){ echo 'selected';} ?> ><?php echo $item['name'];?></option>
                            <?php }?>
                        </select>
                    </td>
                    <td  style="text-align: center;width: 60px;padding-right: 1px;border-right: 0px;">库存数量</td>
                    <td  style="text-align: center;width: 90px;padding-left: 1px;border-left: 0px">
                        <input id="lottery_award_conf_<?php echo $key;?>" type="text" value="<?php if($value['id'] == 0) {echo '0';}else{echo $stock_nums[$value['lottery_award_id']] ??'0';} ?>" class="layui-input"  autocomplete="off" readonly>
                    </td>
                    <td  style="text-align: center;width: 60px;padding-right: 1px;border-right: 0px;">发放数量</td>
                    <td  style="text-align: center;width: 90px;padding-left: 1px;border-left: 0px;border-right: 0px">
                        <input type="text" name="lott_num[]" value="<?php if($value['id'] == 0) {echo '0';}else{echo $value['lott_num'] ??'1';} ?>" class="layui-input"  autocomplete="off">
                    </td>

                    <td  style="text-align: center;width: 60px;padding-right: 1px;border-right: 0px;">位置排序</td>
                    <td  style="text-align: center;padding-left: 1px;border-left: 0px;min-width: 50px">
                        <input type="text" name="sort[]" value="<?php echo $value['sort'] ?? 0; ?>" class="layui-input"  autocomplete="off">
                    </td>
                </tr>
                <?php } ?>
                <?php if(!empty($conf)) {?>
                <tr>
                    <td colspan="4" style="border-right: 0px;text-align: right">
                        <span class="layui-btn"  lay-submit lay-filter="formSubmit" style="width: 100px">确认</span>
                    </td>
                    <td colspan="4" style="border-left: 0px;text-align: left">
                        <span class="layui-btn layui-btn-primary" lay-submit  lay-filter="colse" style="width: 100px">取消</span>
                    </td>
                </tr>
                <?php }?>
                </tbody>
            </table>
            </form>
        </div>
    </div>
</div>
</body>
<script src="/layuiadmin/layui/layui.js"></script>
<script>
    stock_nums_json = <?php echo $stock_nums_json;?>;
    layui.config({
        base: "/layuiadmin/" //静态资源所在路径
    }).extend({
        index: "lib/index", //主入口模块
    }).use(["table", 'form'], function () {
        $ = layui.jquery,table = layui.table, form = layui.form;
        form.on('submit(formSubmit)', function(data){
            layer.confirm('确认要编辑吗？', {icon: 6}, function () {
                $.ajax({
                    type: "POST", //请求方式
                    url: '/admin/rotary_table/prize?id={$model->id}', //请求地址
                    dataType: "json", //返回的数据类型
                    data: $("#sbumitForm").serialize(), //数据
                    //请求成功
                    success: function (data) {
                        if (data.code == 0) {
                            layer.msg(data.msg, {icon: 1, time: 2000}, function () {
                                var index = parent.layer.getFrameIndex(window.name);
                                parent.layer.close(index);
                                window.parent.location.reload();
                            });
                        } else {
                            layer.msg(data.msg, {icon: 2, time: 5000});
                        }
                    }
                });
            });
        });

        form.on('submit(colse)', function(data){
            parent.layer.close(parent.layer.getFrameIndex(window.name));
        });

        form.on('select(lottery_award_id)', function(data){
            var lottery_award_conf = $(data.elem).attr('data');
            if (data.value) {
                $("#lottery_award_conf_" + lottery_award_conf).val(stock_nums_json[data.value]);
            } else {
                $("#lottery_award_conf_" + lottery_award_conf).val(0);
            }
        });
    });
</script>
</html>